package Dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;



import Dao.Daomcone;
import entity.mcone;
import utils.BaseDao;

public class Daoimplmcone extends BaseDao implements Daomcone {

	@Override
	public List<mcone> mconelist() {
		String sql = "select * from mcone";
		ResultSet set = super.executeQuery(sql, null);
		List<mcone> list = new ArrayList<mcone>();
		try {
			while(set.next()){
				list.add(new mcone(set.getInt(1),set.getString(2),set.getString(3)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return list;
	}

	@Override
	public boolean add(mcone one) {
		String sql = "insert into `project`.`mcone` (`menu`, `img`) values (?,?) ";
		Object[] object = {one.getName(),one.getImg()};
		boolean fan = super.executeUpdate(sql, object);
		return fan;
	}

	@Override
	public int sel(mcone one) {
		String sql = "select id from mcone where menu = ? and img = ?";
		Object[] object = {one.getName(),one.getImg()};
		ResultSet set = super.executeQuery(sql, object);
		int id = -1;
		try {
			while(set.next()){
				id=set.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return id;
	}

	@Override
	public boolean del(int id) {
		String sql = "delete from `project`.`mcone` where `id` = ? ";
		Object[] object = {id};
		boolean fan = executeUpdate(sql, object);
		return fan;
	}

}
